<!--三通道当日体现比例-->
<template>
  <div id="main2" style="height: 300px;width: 300px"></div>
</template>

<script lang="ts" setup>
import * as echarts from 'echarts';
import {onMounted, ref} from "vue";
import {getVaccRatioTodayApi} from "../../api/MyIndex";

onMounted(() => {
  getData()
})
interface ChannelData {
  channelName: string | null;
  channelBalance: number | null;
  channelCount: number | null;
}

interface TransformedData {
  value: number;
  name: string;
}

function transformData(data: ChannelData[]): TransformedData[] {
  return data.map((item) => {
    const value = item.channelBalance !== null ? item.channelBalance : 0;
    const name = item.channelName !== null ? item.channelName : '';
    return {value, name};
  });
}

// 示例用法

const dataVal = ref()


function getData() {
  getVaccRatioTodayApi().then((res: any) => {
    dataVal.value = transformData(res.data);
  }).then(() => {
    getChart()
  })

}

function getChart() {
  type EChartsOption = echarts.EChartsOption
  var chartDom = document.getElementById('main2')!;
  var myChart = echarts.init(chartDom);
  var option: EChartsOption;

  option = {
    title: {
      text: '提现比例',
      subtext: '当日',
      left: 'center'
    },
    tooltip: {
      trigger: 'item'
    },
    legend: {
      top: '5%',
      left: 'center'
    },
    series: [
      {
        name: 'Access From',
        type: 'pie',
        radius: ['40%', '70%'],
        avoidLabelOverlap: false,
        itemStyle: {
          borderRadius: 10,
          borderColor: '#fff',
          borderWidth: 2
        },
        label: {
          show: false,
          position: 'center'
        },
        emphasis: {
          label: {
            show: true,
            fontSize: '40',
            fontWeight: 'bold'
          }
        },
        labelLine: {
          show: false
        },
        data:dataVal.value
      }
    ]
  };

  option && myChart.setOption(option);


}

</script>

<style scoped>

</style>